package dao.support.sql;

import java.util.ArrayList;
import java.util.List;

import support.GridResult;

public class SqlObject {
	private String entity = "";
	private String sord;
	private int page;
	private String sidx;
	private int rows;
	private String condition;
	private String field;
	private String count_entity;

	public SqlObject(String entity, String sord, int page, String sidx, int rows) {
		this.entity = entity;
		this.sord = sord;
		this.page = page;
		this.sidx = sidx;
		this.rows = rows;
	}
	public SqlObject(String entity,String count_entity, String sord, int page, String sidx, int rows) {
		this.entity = entity;
		this.sord = sord;
		this.page = page;
		this.sidx = sidx;
		this.rows = rows;
		this.count_entity = count_entity;
	}


	public String getSqlCount() {
		String sql;
		if(this.count_entity!=null)
			sql = "select count("+count_entity+") as c from " + entity + " where "+ condition;
		else
		    sql = "select count(*) as c from " + entity + " where "+ condition;
		return sql;
	}

	public String getSqlRows() {
		String sql = "select " + field + " from " + entity + " where "
				+ condition + " order by " + sidx + " " + sord + " limit "
				+ (page - 1) * rows + "," + rows;
		return sql;
	}


	public String getEntity() {
		return entity;
	}


	public void setEntity(String entity) {
		this.entity = entity;
	}


	public String getCondition() {
		return condition;
	}


	public void setCondition(String condition) {
		this.condition = condition;
	}


	public String getField() {
		return field;
	}


	public void setField(String field) {
		this.field = field;
	}


	public String getSord() {
		return sord;
	}

	public void setSord(String sord) {
		this.sord = sord;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getSidx() {
		return sidx;
	}

	public void setSidx(String sidx) {
		this.sidx = sidx;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	} 
}
